Skip to content

stm32: do not declare ADC interrupts unless using SIMPLEFOC_STM32_ADC_INTERRUPT - #546

Open
Moddingear wants to merge 1 commit into
simplefoc:devfrom
Moddingear:stm32_free_adc_isr
Open

Moddingear wants to merge 1 commit into
simplefoc:devfrom
Moddingear:stm32_free_adc_isr

Conversation

@Moddingear

@Moddingear Moddingear commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Removing the definition of interrupt handlers if no interrupts used

@dekutree64

dekutree64 commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Looks good. I usually use DMA for the ADC results, but have used interrupts as well, and had to hunt down that function in the library code and disable it. Better to control it with a #define so you don't have to modify the library code.

@askuric

askuric commented Oct 4, 2026

Copy link
Copy Markdown
Member

Hey @Moddingear ,

This will not work in oour case.
We do use interrupts in the library actually.

When the timer does not have interrupt counter we use interrupt callback to downsample the readings.
If the timer does have the repetition counter we do not use interrupts.

The proposed PR woudl break the readings on timers without repetition counter.

So we might add a new flag somewhere called
SIMPLEFOC_STM32_ADC_DISABLE_RC_FALLBACK

And condition the ADC handlers on this maybe. If this flag is not defined then the interrupts are not allowed and you can condition the adc handler definitions on this.

@Moddingear

Copy link
Copy Markdown
Contributor Author

Modified as requested.

@askuric

askuric commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thanks for updating the pr and going forward with this.
But if I'm not mistaking this change is not what I ment.

Basically we do need the old flag and it did what we need it to do.
SIMPLEFOC_STM32_ADC_INTERUPT should stay unchanged.
If this flag is defined the ADC is forced to use interrupts.

If the flag is not defined that is where the nuance happens.

  1. If the timer has repetition counter no interrupts are used,
    2.I f the timer hasn't repetition counter the interrupts ARE used.

The new flag (SIMPLEFOC_STM32_ADC_DISABLE_RC_FALLBACK) should not just be the inverse of the old flag, but disable the behaviour in the case 2.
And if the vase 2. Is disabled then this flag also can condition the ADC handlers, which you already have done.

So what I would like you to do, if we want this PR to work is to modify the lines of family files to return error if there is no repetition counter and the interrupt is disabled:

if(tim_interrupt) {
  // error in the timer interrupt initialization
    SIMPLEFOC_DEBUG("STM32-CS: timer has no repetition counter, ADC interrupt has to be used");
#ifdef SIMPLEFOC_STM32_ADC_DISABLE_RC_FALLBACK
   SIMPLEFOC_DEBUG("STM32-CS: ERROR: Interrupts disabled!");
   return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED;
#endif
  }

@Moddingear

Copy link
Copy Markdown
Contributor Author

@askuric Something like that ?

The handlers are registered only if SIMPLEFOC_STM32_ADC_DISABLE_RC_FALLBACK isn't defined, and there's the error when trying to use repetition counters with it defined.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants